package com.wavecoler.professor.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.wavecoler.professor.objects.Problem;

public class InitiateSession extends HttpServlet{

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String id = req.getParameter("idProb");
		System.out.println("Wiii el numero de problema es: " + id);
		int idproblema = Integer.parseInt(id);
		ArrayList<Problem> problema = (ArrayList<Problem>) req.getSession().getAttribute("problems");
		Problem chidi = new Problem();
		for(int i = 0; i < problema.size();i++){
			Problem malo = problema.get(i);
			System.out.println(malo.getUrlPage());
			if(malo.getProblemId() == idproblema){
				chidi = malo;
				break;
			}
		}
		
		HttpSession holo = req.getSession();
		
		holo.setAttribute("Problema",chidi);
		
		 String address = "jsps/ShowProblem.jsp";
		    RequestDispatcher dispatcher = req.getRequestDispatcher(address);
		    dispatcher.forward(req, resp);
	}

}
